//
//  ServiceCategoriesViewController.swift
//
//
//  Created by Ralf on 6/12/15.
//
//

import UIKit

class ServiceCategoriesL2Delegate: NSObject, UICollectionViewDataSource, UICollectionViewDelegate
{
    var activityViewController:MarketViewController!
    var dataIndex:              Int     = 0
    let dataSource:             NSArray = [[["服装", "SC-ImageManagement-0.png"], ["珠宝", "SC-ImageManagement-1.png"], ["鞋子", "SC-ImageManagement-2.png"]],

                                           [["箱包", "SC-Creative-0.png"], ["绘画", "SC-Creative-1.png"], ["皮艺", "SC-Creative-2.png"], ["纸艺", "SC-Creative-3.png"], ["陶艺", "SC-Creative-4.png"], ["女红", "SC-Creative-5.png"], ["纹身", "SC-Creative-6.png"], ["玩具", "SC-Creative-7.png"]],

                                           [["乐器", "SC-Civilization-0.png"], ["茶艺", "SC-Civilization-1.png"], ["陶艺", "SC-Creative-4.png"], ["文玩", "SC-Civilization-2.png"], ["绘画", "SC-Creative-1.png"]],

                                           [["家具", "SC-DreamHome-0.png"], ["装修", "SC-DreamHome-1.png"], ["园艺", "SC-DreamHome-2.png"], ["女红", "SC-Creative-5.png"], ["修理", "SC-DreamHome-3.png"]],

                                           [["美食", "SC-TasteLife-0.png"], ["布艺", "SC-TasteLife-1.png"], ["美妆", "SC-TasteLife-2.png"], ["健康", "SC-TasteLife-3.png"], ["茶艺", "SC-Civilization-1.png"], ["酒水类", "SC-TasteLife-4.png"], ["纹身", "SC-Creative-6.png"]],

                                           [["电子科技", "SC-Technology-0.png"]]]

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    {
        return dataSource.objectAtIndex(dataIndex).count
    }
    
     func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        //#warning Incomplete method implementation -- Return the number of sections
        return 1
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
    {
        let cell: SecondCategoryCell
        = collectionView.dequeueReusableCellWithReuseIdentifier("SecondCell", forIndexPath: indexPath) as! SecondCategoryCell
        cell.setData(dataSource[dataIndex][indexPath.item].objectAtIndex(0) as! String, imageName: dataSource[dataIndex][indexPath.item].objectAtIndex(1) as! String)

        return cell
    }

    func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool
    {
        return true
    }

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
    {
        let cell: UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!
        let label                      = cell.viewWithTag(20) as! UILabel
        //点击

        activityViewController.serviceCategories = label.text
        activityViewController.reloadData(self)
        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        appDelegate.navigationController.popToRootViewControllerAnimated(true)

    }
}
